;***********************************************************
; csv_2.ncl
;
; Concepts illustrated:
;   - Reading a CSV file
;   - Using str_get_field to parse a string
;   - Using conversion functions to convert strings to numeric values
;   - Reading an ASCII file with delimiters
;
;***********************************************************
; This is an example of reading a CSV file that has string,
; integer, and float fields.
;***********************************************************
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"

begin
  filename = "YLJ_precip_stnlist.txt"

;---Read in file as array of strings so we can parse each line
  lines = readAsciiTable(filename,1,"string",1)

  delim = ","

;---Read fields 1, 5 and 9
  name   = ndtooned(str_get_field(lines,1,delim))
  number = ndtooned(str_get_field(lines,2,delim))
  lat    = ndtooned(tofloat(str_get_field(lines,3,delim)))
  lon    = ndtooned(tofloat(str_get_field(lines,4,delim)))
  domain = ndtooned(str_get_field(lines,5,delim))

;---Print the information
  print("Name is '" + name + "', number is " + number + ", lat is " + lat + ", lon is " + lon + ", domain is " + domain)
end
print(name)
print(lat)
print(lon)
